package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.Constant;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.xml.ExpertInfoXML;
import com.digitalchina.lxnsy.xml.PersonalInfoXML;
import com.digitalchina.lxnsy.xml.UserXML;
import com.lzy.okhttputils.model.HttpParams;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.api
 * 创建人：郑皓
 * 创建时间：2018/8/10 15:03
 * 修改备注：
 * ================================================
 */
public class BusinessShareFarm {

    /**
     * 共享类型
     *
     * @param activity
     * @param handler
     */
    public static void shareFarmType(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("pCode","AGRICULTURE_TYPE");
        OkHttpUtil.get(activity, URL.URL_SHARE_FARM_TYPE, "", params, handler, MSG.MSG_SHARE_FARM_TYPE_SUCCESS, MSG.MSG_SHARE_FARM_TYPE_FIELD);

    }


    /**
     * 共享列表
     *
     * @param activity
     * @param page
     * @param num
     * @param type     共享类型code
     * @param name     共享名称
     * @param handler
     */
    public static void shareList(Activity activity, int page, int num, String type, String name,String queryDataType, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("page", String.valueOf(page));
        params.put("perPage", String.valueOf(num));
        params.put("typeCode", type);
        params.put("name", name);
        params.put("queryDataType", queryDataType);
        OkHttpUtil.get(activity, URL.URL_SHARE_FARM_LIST, "", params, handler, MSG.MSG_SHARE_FARM_LIST_SUCCESS, MSG.MSG_SHARE_FARM_LIST_FIELD);

    }


    /**
     * 猜我喜欢
     *
     * @param activity
     * @param handler
     */
    public static void getLoveShare(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccid", UserXML.getUserId(activity));


        OkHttpUtil.post(activity, URL.URL_GET_LOVE_SHARE, "", params, handler, MSG.MSG_GET_LOVE_SHARE_SUCCESS, MSG.MSG_GET_LOVE_SHARE_FIELD);

    }

    /**
     * @param activity
     * @param productId 农产品ID
     * @param isDetail  操作类型（详情传：details 其他不传）
     * @param handler
     */
    public static void getRegions(Activity activity, String productId, boolean isDetail, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("productId", productId);
        if (isDetail)
            params.put("addressType", "details");


        OkHttpUtil.post(activity, URL.URL_GET_REGIONS, "获取数据中", params, handler, MSG.MSG_GET_REGIONS_SUCCESS, MSG.MSG_GET_REGIONS_FIELD);

    }

    /**
     * 获取发布共享基础数据
     *
     * @param activity
     * @param handler
     */
    public static void getPublishShareBasicData(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_GET_SHARE_BASIC_DATA, "", params, handler, MSG.MSG_GET_SHARE_BASIC_DATA_SUCCESS, MSG.MSG_GET_SHARE_BASIC_DATA_FIELD);

    }
    /**
     * 获取发布共享基础数据
     *
     * @param activity
     * @param handler
     */
    public static void getPublishShareBasicData1(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("pCode","AGRICULTURE_TYPE");

        OkHttpUtil.get(activity, URL.URL_GET_SHARE_BASIC_DATA1, "", params, handler, MSG.MSG_GET_SHARE_BASIC_DATA_SUCCESS, MSG.MSG_GET_SHARE_BASIC_DATA_FIELD);

    }

    /**
     * 共享 生成订单
     *
     * @param activity
     * @param consignee        收货人
     * @param shippingProvince 省
     * @param shippingCity     市
     * @param shippingCounty   区
     * @param shippingDetail   收货地址详细地址
     * @param shippingPhone    联系电话
     * @param tip              买家备注
     * @param totalEnsureMoney 总保证金字段
     * @param orderType        订单类型 0预订 1直接购买 ，2出租, 3出售
     * @param orderVOList      订单 列表json格式
     * @param handler
     */
    public static void generateOrders(Activity activity, String consignee, String shippingProvince, String shippingCity, String shippingCounty, String shippingDetail, String shippingPhone, String tip, String totalEnsureMoney,
                                      String orderType, String orderVOList, Handler handler) {

        String name = "";
        String img = "";
        if (UserXML.getUserType(activity).equals(Constant.USER_TYPE_EXPERT)) {
            //专家用户
            name = ExpertInfoXML.getExpertName(activity);
            img = URL.URL_SHOW_IMAGE + ExpertInfoXML.getPhoto(activity) + Constant.SHOW_IMAGE_TYPE_MID;
        } else {
            //个人用户
            if (!StringUtil.isStrEmpty(UserXML.getUserTrueName(activity)))
                name = UserXML.getUserTrueName(activity);
            else
                name = UserXML.getLoginName(activity);

            img = URL.URL_SHOW_IMAGE + PersonalInfoXML.getHeadportrait(activity) + Constant.SHOW_IMAGE_TYPE_MID;

        }

        HttpParams params = new HttpParams();
        params.put("buyerId", UserXML.getUserId(activity));
        params.put("buyerName", name); // 买家姓名
        params.put("buyerLogo", img); // 买家头像
        params.put("consignee", consignee);
        params.put("shippingProvince", shippingProvince);
        params.put("shippingCity", shippingCity);
        params.put("shippingCounty", shippingCounty);
        params.put("shippingDetail", shippingDetail);
        params.put("shippingPhone", shippingPhone);
        params.put("tip", tip);
        params.put("paymentType", "1"); // 支付类型 0-线下支付，1-在线支付
        params.put("appChannel", "1"); // 应用渠道  PC：0，移动端：1
        params.put("totalEnsureMoney", totalEnsureMoney);
        params.put("orderType", orderType);
        params.put("orderVOList", orderVOList);

        OkHttpUtil.post(activity, URL.URL_SHARE_GENERATE_ORDERS, "请稍候...", params, handler, MSG.MSG_SHARE_GENERATE_ORDERS_SUCCESS, MSG.MSG_SHARE_GENERATE_ORDERS_FIELD);

    }


    /**
     * 发布/编辑共享
     *
     * @param activity
     * @param productId                     共享产品id
     * @param name                          共享名称
     * @param type                          共享分类code
     * @param shareType                     共享方式
     * @param sharePrice                    共享价格
     * @param salePrice                     出售价格
     * @param unit                          共享价格单位code
     * @param securityDeposit               保证金
     * @param productNum                    共享数量
     * @param deliveryMode                  取送方式
     * @param retentionAddress              自提地址
     * @param isFreePostage                 运费设置 1-包邮  0-设置邮费
     * @param postage                       邮费
     * @param shareScopeFlag                共享范围类型 1-不限 0-限制范围
     * @param agricultureProductShareScopes 范围类型
     * @param mainImage                     主图
     * @param introduce                     详情
     * @param pictures                      详情图片(以逗号隔开)
     * @param handler
     */
    public static void publishShareProductMobile(Activity activity, String productId, String name, String type, String shareType, String sharePrice, String salePrice, String unit, String securityDeposit,
                                                 String productNum, String deliveryMode, String retentionAddress, String isFreePostage, String postage, String shareScopeFlag, String agricultureProductShareScopes,
                                                 String mainImage, String introduce, String pictures, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));
        params.put("productId", productId);
        params.put("name", name);
        params.put("type", type);
        params.put("shareType", shareType);
        params.put("sharePrice", sharePrice);
        params.put("salePrice", salePrice);
        params.put("unit", unit);
        params.put("securityDeposit", securityDeposit);
        params.put("productNum", productNum);
        params.put("deliveryMode", deliveryMode);
        params.put("retentionAddress", retentionAddress);
        params.put("isFreePostage", isFreePostage);
        params.put("postage", postage);
        params.put("shareScopeFlag", shareScopeFlag);
        params.put("agricultureProductShareScopes", agricultureProductShareScopes);
        params.put("mainImage", mainImage);
        params.put("introduce", introduce);
        params.put("pictures", pictures);


        OkHttpUtil.post(activity, URL.URL_PUBLISH_SHARE_PRODUCT, "发布中，请稍候...", params, handler, MSG.MSG_PUBLISH_SHARE_PRODUCT_SUCCESS, MSG.MSG_PUBLISH_SHARE_PRODUCT_FIELD);

    }


    /**
     * 获取共享买家订单列表
     *
     * @param activity
     * @param queryStatus  状态：
     *                     （不需要发货、自提）
     *                     10 -"待提货"
     *                     11 - "待评价"
     *                     12 - "已关闭"
     *                     19 - "待支付"
     *                     （邮寄）
     *                     20 - "待发货"
     *                     21 - "待收货"
     *                     22 - "待评价"
     *                     23 - "已关闭"
     *                     29 - "待支付"
     *                     31 - "待评价"，不区分自提邮寄
     *                     32 - "已关闭"，不区分自提邮寄
     *                     39 - "待付款"，不区分自提邮寄
     * @param shippingType 发货类型：0-不需发货  1-自提  2-邮寄  为空时默认查询邮寄和自提
     * @param page
     * @param limit
     * @param handler
     */
    public static void getBuyerOrderList(Activity activity, String queryStatus, String shippingType, String page, String limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("buyerId", UserXML.getUserId(activity));
        params.put("orderNo", ""); // 订单编号，如果传，则模糊匹配
        params.put("page", page);
        params.put("limit", limit);
        params.put("queryStatus", queryStatus);
        params.put("shippingType", shippingType);

        OkHttpUtil.post(activity, URL.URL_GET_BUYER_ORDER_LIST, "", params, handler, MSG.MSG_GET_BUYER_ORDER_LIST_SUCCESS, MSG.MSG_GET_BUYER_ORDER_LIST_FIELD);

    }

    /**
     * 获取销售订单列表 全部订单
     *
     * @param activity
     * @param page
     * @param limit
     * @param handler
     */
    public static void getSellerOrderList(Activity activity, String page, String limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("sellerId", UserXML.getUserId(activity));
        params.put("page", page);
        params.put("limit", limit);

        OkHttpUtil.post(activity, URL.URL_GET_ORDER_LIST_ALL, "", params, handler, MSG.MSG_GET_ORDER_LIST_4_SHARE_PLAT_SUCCESS, MSG.MSG_GET_ORDER_LIST_4_SHARE_PLAT_FIELD);

    }

    /**
     * 获取销售订单列表 按照状态查询
     *
     * @param activity
     * @param queryStatus
     * @param shippingType
     * @param page
     * @param limit
     * @param handler
     */
    public static void getSellerOrderList(Activity activity, String queryStatus, String shippingType, String page, String limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("sellerId", UserXML.getUserId(activity));
        params.put("orderNo", ""); // 订单编号，如果传，则模糊匹配
        params.put("page", page);
        params.put("limit", limit);
        params.put("queryStatus", queryStatus);
        params.put("shippingType", shippingType);

        OkHttpUtil.post(activity, URL.URL_GET_ORDER_LIST_4_SHARE_PLAT, "", params, handler, MSG.MSG_GET_ORDER_LIST_4_SHARE_PLAT_SUCCESS, MSG.MSG_GET_ORDER_LIST_4_SHARE_PLAT_FIELD);

    }


    /**
     * 卖家验证提货码
     *
     * @param activity
     * @param orderNo          订单编号
     * @param verificationCode 验证码
     * @param handler
     */
    public static void pickUpVerification(Activity activity, String orderNo, String verificationCode, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("orderNo", orderNo);
        params.put("verificationCode", verificationCode);

        OkHttpUtil.post(activity, URL.URL_PICK_UP_VERIFICATION, "", params, handler, MSG.MSG_PICK_UP_VERIFICATION_SUCCESS, MSG.MSG_PICK_UP_VERIFICATION_FIELD);

    }

    /**
     * 卖家办理取货
     *
     * @param activity
     * @param orderNo  订单号
     * @param sellerId 卖家ID
     * @param handler
     */
    public static void affirmBuyerPickup(Activity activity, String orderNo, String sellerId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("orderNo", orderNo);
        params.put("sellerId", sellerId);

        OkHttpUtil.post(activity, URL.URL_AFFIRM_BUYER_PICKUP, "", params, handler, MSG.MSG_AFFIRM_BUYER_PICKUP_SUCCESS, MSG.MSG_AFFIRM_BUYER_PICKUP_FIELD);

    }

    /**
     * 获取所有物流
     *
     * @param activity
     * @param handler
     */
    public static void getLogisticsCompanies(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_GET_LOGISTICS_COMPANIES, "", params, handler, MSG.MSG_GET_LOGISTICS_COMPANIES_SUCCESS, MSG.MSG_GET_LOGISTICS_COMPANIES_FIELD);

    }

    /**
     * 快照
     *
     * @param activity
     * @param product_SN SN号
     * @param handler
     */
    public static void getShareDetailByNo(Activity activity, String product_SN, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("product_SN", product_SN);

        OkHttpUtil.post(activity, URL.URL_GET_SHARE_PRODUCT_DETAIL_BY_NO, "", params, handler, MSG.MSG_GET_SHARE_PRODUCT_DETAIL_BY_NO_SUCCESS, MSG.MSG_GET_SHARE_PRODUCT_DETAIL_BY_NO_FIELD);

    }


    /**
     * 卖家确认发货
     *
     * @param activity
     * @param orderNo          订单编号
     * @param deliveryCorp     物流公司
     * @param trackingNo       物流单号
     * @param deliveryCorpCode 物流公司代码
     * @param handler
     */
    public static void affirmShipments(Activity activity, String orderNo, String deliveryCorp, String trackingNo, String deliveryCorpCode, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("sellerId", UserXML.getUserId(activity));
        params.put("orderNo", orderNo);
        params.put("deliveryCorp", deliveryCorp);
        params.put("trackingNo", trackingNo);
        params.put("deliveryCorpCode", deliveryCorpCode);

        OkHttpUtil.post(activity, URL.URL_AFFIRM_SHIPMENTS, "", params, handler, MSG.MSG_AFFIRM_SHIPMENTS_SUCCESS, MSG.MSG_AFFIRM_SHIPMENTS_FIELD);

    }


    /**
     * 获取商户共享列表
     *
     * @param activity
     * @param page
     * @param limit
     * @param handler
     */
    public static void getShareListByUser(Activity activity, String userAccId, int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", userAccId);
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_GET_SHARE_LIST_BY_USER, "", params, handler, MSG.MSG_GET_SHARE_LIST_BY_USER_SUCCESS, MSG.MSG_GET_SHARE_LIST_BY_USER_FIELD);

    }

    /**
     * 获取商户共享列表
     *
     * @param activity
     * @param page
     * @param limit
     * @param handler
     */
    public static void getActivityListByUser(Activity activity, String userAccId, int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", userAccId);
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_GET_ACTIVITY_LIST_BY_USER, "", params, handler, MSG.MSG_GET_ACTIVITY_LIST_BY_USER_SUCCESS, MSG.MSG_GET_ACTIVITY_LIST_BY_USER_FIELD);

    }


    /**
     * 我的共享列表
     *
     * @param activity
     * @param status   0-已下架 1-上架中
     * @param page
     * @param limit
     * @param handler
     */
    public static void getUserShare(Activity activity, String status, int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("user", UserXML.getUserId(activity));
        params.put("status", status);
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_GET_USER_SHARE, "", params, handler, MSG.MSG_GET_USER_SHARE_SUCCESS, MSG.MSG_GET_USER_SHARE_FIELD);

    }


    /**
     * 共享商品上架
     *
     * @param activity
     * @param productId
     * @param handler
     */
    public static void onlineAgricultureProduct(Activity activity, String productId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("productId", productId);

        OkHttpUtil.post(activity, URL.URL_ONLINE_AGRICULTURE_PRODUCT, "", params, handler, MSG.MSG_ONLINE_AGRICULTURE_PRODUCT_SUCCESS, MSG.MSG_ONLINE_AGRICULTURE_PRODUCT_FIELD);

    }

    /**
     * 共享商品下架
     *
     * @param activity
     * @param productId
     * @param handler
     */
    public static void offlineAgricultureProduct(Activity activity, String productId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("productId", productId);

        OkHttpUtil.post(activity, URL.URL_OFFLINE_AGRICULTURE_PRODUCT, "", params, handler, MSG.MSG_OFFLINE_AGRICULTURE_PRODUCT_SUCCESS, MSG.MSG_OFFLINE_AGRICULTURE_PRODUCT_FIELD);

    }

    /**
     * 共享商品详情
     *
     * @param activity  产品id
     * @param productId 共享分类code
     * @param type
     * @param handler
     */
    public static void getShareProductDetail(Activity activity, String productId, String type, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("type", type);

        OkHttpUtil.get(activity, URL.URL_GET_SHARE_PRODUCT_DETAIL+productId, "", params, handler, MSG.MSG_GET_SHARE_PRODUCT_DETAIL_SUCCESS, MSG.MSG_GET_SHARE_PRODUCT_DETAIL_FIELD);

    }

    /**
     * 共享区域校验接口
     *
     * @param activity
     * @param productId
     * @param shippingProvince
     * @param shippingCity
     * @param shippingCounty
     * @param handler
     */
    public static void isAllSharingScope(Activity activity, String productId, String shippingProvince, String shippingCity, String shippingCounty, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("productId", productId);
        params.put("shippingProvince", shippingProvince);
        params.put("shippingCity", shippingCity);
        params.put("shippingCounty", shippingCounty);

        OkHttpUtil.post(activity, URL.URL_IS_ALL_SHARING_SCOPE, "请稍等...", params, handler, MSG.MSG_IS_ALL_SHARING_SCOPE_SUCCESS, MSG.MSG_IS_ALL_SHARING_SCOPE_FIELD);

    }
}
